<?php

require_once SMARTY_DIR.'Smarty.class.php';

class MVC_View {
    var $template;
    var $template_dir;

    function MVC_View() {
        $this->template = new Smarty;

        $this->template->compile_check = TRUE;
        $this->template->template_dir = SMARTY_TEMPLATE_DIR;
        $this->template->compile_dir =  SMARTY_COMPILE_DIR;
        $this->template->config_dir = LANG_DIR;

        $this->setTemplateDir();
    }

    function setTemplateDir($dir = "") {
        $this->template_dir = $dir;
    }

    function assign($name, $data) {
        $this->template->assign($name, $data);
    }

    function display($template = "") {
        $this->assign('smarty_tela', $template.".tpl");
        print mb_convert_encoding( $this->fetch('base'), 'HTML-ENTITIES', 'auto' );
    }

    function fetch($template = "") {
        if (empty($template)) {
            exit("No template assigned");
        }
        $this->template->caching = 0;
        $content = $this->template->fetch(  $this->template_dir . $template . '.tpl');
        $this->template->clear_all_cache();
        return $content;
    }

}
?>
